<?php
	$ssFilter = $this->arrParam['ssFilter'];
	$langTmp = $ssFilter['lang'];
	if($langTmp == ''){
		$langTmp = 'vi';
	}else{
		$langTmp = $ssFilter['lang'];
	}
	
	$page = 1;
	
	$lang = $this->arrParam['lang'];
    if(empty($lang)){
    	$lang = 'vi';
    }else{
    	$lang = $this->arrParam['lang'];
    }
	
	$urlHome 		= array('module'=>'default','controller'=>'index','action'=>'index','lang'=>$langTmp);
   	$linkHome 		= $this->url($urlHome,'home');
?>

<?php
	$item = $this->Item;
	
	$name = $item['name'];
	$summary 	= $item['summary'];
	$summary 	= str_replace("\\"," ",$summary);
	$content 	= $item['content'];
	$content 	= str_replace("\\"," ",$content);
	$created 	= $item['created'];
	
	if(!empty($item['picture'])){
	    $linkImg	= FILES_URL . '/news/images450x450/' . $item['picture'];
	    $linkImg2	= FILES_URL . '/news/orignal/' . $item['picture'];
	    $picture 	= '<img src="'. $linkImg .'" alt="'.$name.'" />';
	    $image 		= '<img src="'. $linkImg .'" alt="'.$name.'" />';
    }else{
	    $linkImg	= FILES_URL . '/news/images100x100/no-image.jpg';
	    $picture 	= '<img src="'. $linkImg .'" alt="'.$name.'" />';
	    $image 		= '<img src="'. $linkImg .'" alt="'.$name.'" />';
    }
    $cat 		= $this->Cat;
    $category	= $cat['name'];
    $urlOptions = array('module'=>'news','controller'=>'index',
						'action'=>'category',
                    	'tid'=> $this->arrParam['nid'],
						'name'=>$cat['alias'],
                    	'lang'=>$lang,
                    	'page'=>$page);
   	$linkDetail = $this->url($urlOptions,'news-category');
   	$id = $item['id'];
?>
<script type="text/javascript">
		function fancyBox(elem){
			elem = $(elem);
			if (!elem.data("fancybox")) {
				elem.data("fancybox", true);
				elem.fancybox({
					'titleShow' 	: false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'centerOnScroll': true
				}).trigger('click');
			}
			return false; 
		}
	</script>
<div class="left">
                <div class="content-left bag-white">
                	<div class="detail">
                		<div class="sub-content color-blue mar-btn-20"><a class="color-blue" href="<?php echo $linkHome?>">Home</a> &#187; <a title="<?php echo $category?>" class="color-blue" href="<?php echo $linkDetail?>"><?php echo $category?></a> &#187; <?php echo $name?></div>
                    	<!--------------------BOX CONTENT (Start) -------------------->
                        <div class="box-cnt col-0">
                            <div class="bor-img">
                                <a onclick="return fancyBox(this);" id="various1" href="#inline1" title="<?php echo $name?>"><?php echo $picture?></a>
                            </div>
                            <div class="desc">
                                <h1 class="color-blue"><?php echo $name?></h1>
                                <p class="creat-day"><?php echo $created?></p>
                                <p class="summary"><?php echo $summary?></p>
                            </div>
                            <div class="clear"></div>
                            <div class="line"></div>
                        </div>
                        <div class="clear"></div>
                        <div class="cnt-detail">
                        	<!--<h1 class="color-blue"><?php echo $name?></h1>-->
                        	<?php echo $content?>
                        	<button class="btn-comment">Góp ý kiến</button>
                        	<?php
                        		$info = new Zendvn_System_Info();
								$memberInfo = $info->getMemberInfo('id');
								if($memberInfo != ''){
									$tbltUser 	= new Zendvn_Models_Users();
									$user 		= $tbltUser->listItem($this->arrParam,array('user_id'=>$memberInfo,'task'=>'public'));
									$group_id 	= $user['group_id'];
								}
								$email		=	$this->formText('email',null,array("class"=>"text"));
								$full_name	=	$this->formText('full_name',null,array("class"=>"text"));
								$email		=	$this->formText('email',null,array("class"=>"text"));
								$title		= 	$this->formText('title',null,array("class"=>"text"));
								$hidden		= 	$this->formHidden('news_id',$id,array("class"=>"text"));
								$hidUser	= 	$this->formHidden('user_id',$group_id,array("class"=>"text"));
								$content	= 	$this->formTextarea('content',null,array('rows'=>10));
								
								$captcha 	= 	$this->captcha;
								$txtCaptcha = 	$this->formText('captcha','');
								$txtID 		= 	$this->formHidden('captchaID',$this->captcha_id);		
								$urlCaptch	= $this->baseUrl('default/index/captcha-image');	
								$inputCaptcha	= $this->formText('captcha',null,array("class"=>"code text"));
								
								$submit		= $this->formSubmit('submit','Gửi bình luận',array("class"=>"btn-submit"));
								
								
								$formFullname 	= '<div class="lev">
													<span class="sub">Họ tên</span>'
													. $full_name . '</div>';
													
								$formEmail 		= '<div class="lev">
													<span class="sub">Email</span>'
													. $email . '</div>';
													
								$formTitle 		= '<div class="lev">
													<span class="sub">Tiêu đề</span>'
													. $title . $hidden . $hidUser .'</div>';
													
								$formContent 	= '<div class="lev">
												<span class="sub">Nội dung</span>'
												. $content . '</div>';
												
								$formSubmit  	= '<div class="lev">'
												. $submit .
												'</div>';
												
								if($group_id > 0){
									$input = $formTitle . $formContent ;
								}else{
									$input = $formFullname . $formEmail . $formTitle . $formContent ;
								}
                        	?>
                        	<!-- ================comment================== -->
                        	<div id="content-load" class="note"></div>
                        	<div id="comment" class="comment">
                        		<?php
                        			$linkSubmit =  $this->baseUrl($this->currentController . '/comment');
                        		?>
                        		<form id="cnt-comment" action="<?php echo $linkSubmit ;?>" method="post">
                        			<?php echo $input?>
                        			
                        			<div class="lev">
						                  <span>Mã xác nhận: </span>
						                  <div>
						                  	<?php echo $inputCaptcha;?>                            	
						                  	<?php if(!empty($this->messageError['captcha'])):echo '<p class="msg_error">'.$this->messageError['captcha'].'</p>';endif;?>
						                  </div>	
						            </div>
						            <div class="lev">
						             	<div>
											<div class="border-img"><?php echo $txtID . $captcha;?></div>
						             	  </div>
						             </div>
                        			
                        			<?php echo $formSubmit?>
                        		</form>
							</div>
							<!-- ================comment================== -->
							
							<div class="task-comments">
									<?php
										$comment = new Zendvn_Models_CommentsNews();
		                        		$listCom = $comment->listItem($this->arrParam, array('task'=>'list'));
		                        		if(!empty($listCom)){
			                        		foreach ($listCom as $key => $val){
			                        			$title 		= htmlentities($val['title'],null,"UTF-8");
			                        			$user_name 	= $val['user_name'];
			                        			$created 	= $val['created'];
			                        			$content 	= htmlentities($val['content'],null,"UTF-8");
			                        			if($key%2 == 0){
			                        				$cls = 'row-0';
			                        			}else{
			                        				$cls = 'row-1';
			                        			}
									?>
                        			<div class="box-comment <?php echo $cls?>">
                        				<h3 class="color-blue"><?php echo $title?></h3>
                        				<span class='crt-comment'>22-11-2012</span>
                        				<span class='user'><?php echo $user_name;?></span>
                        				<div class="clear"></div>
                        				<div class="cnt-comment"><?php echo $content?></div>
                        			</div>
                        			<?php }}?>
                        	</div>
                            <div class="relate-news mar-top-20">
                                <h3 class="color-blue">Các tin tức nổi bật</h3>
                                <div class="list-relate">
                                	<?php
                                		foreach ($this->ItemCat as $key => $val){
                                			$name = $val['name'];
                                			$lang = $this->arrParam['lang'];
						                    if(empty($lang)){
						                    	$lang = 'vi';
						                    }else{
						                    	$lang = $this->arrParam['lang'];
						                    }
						                    $urlOptions = array('module'=>'news','controller'=>'index',
																			'action'=>'detail',
																			'nname'=>$val['alias_name'],
																			'title'=>$val['alias'],
						                    								'nid'=> $val['cat_id'],
																			'id'=>$val['id'],
						                    								'lang'=>$lang);
						                    $linkDetail = $this->url($urlOptions,'news-detail');
                                	?>
                                    <p><a class="li" href="<?php echo $linkDetail?>"><?php echo $name?></a></p>
                                    <?php }?>
                                </div>
                            </div>
                            
                        </div>
                        <!--------------------BOX CONTENT (End) ----------------------> 
                    </div>
                </div>
                <!-----------------CONTENT (END) -------------------->
</div>      
				<div style="display: none;">
					<div id="inline1" style="width:auto;height:auto;overflow:auto;">
							<?php echo $image?>
					</div>
				</div>
				
<script type="text/javascript">
	//Khai bao ten cua form
	var formID = '#cnt-comment';
	//Khai bao ten cua vung hien du lieu tra ve
	var formMessage = '#content-load';
	var options = {
				target: formMessage,
				dataType: "json", 
				success: processData,
				};
	$(document).ready(function(){
		$(formMessage).ajaxSend(function(){
				$(formMessage).removeClass().addClass('loading').html('<img src="<?php echo $this->imgUrl . '/ajax-loader.gif';?>" alt="loading" />').fadeIn();
		});
		$(formID).submit(function(){
				$(this).ajaxSubmit(options);
				return false;
		});
	});

	function processData(data){
		if(data.type == 0){
			var success = 'Du lieu data duoc luu vao database';
			$(formMessage).addClass('success').html(success).fadeIn();
			$(formID).resetForm();
			$('#comment').slideUp(500);
			//$(formMessage).hide(10000);
			$(formMessage).delay(1500).fadeOut('slow');
			
		}else{
			var error = '';
			var msgError = data.err;
			for(x in msgError){
				error = error + msgError[x] + '<br>';
			}
			$(formMessage).removeClass().addClass('errors').html(error).fadeIn();
		}		
	}
</script>			
<script type="text/javascript">
	$('.btn-comment') .click(function(){
		$('#comment').slideToggle();
	})	
</script>

<script>
	function getData(data){
		$('.border-img').html(data);
		return false;
	}
	
	function refreshCaptcha(){
		var captchaID = $("#captchaID").val();
		$.get('<?php echo $urlCaptch . '/captchaID/';?>'+captchaID,getData);
	}
	$(document).ready(function(){
		$('#refresh').click(function(e){
			e.preventDefault();
			refreshCaptcha();
		});
	});
</script>
